Ext.define('appfe.view.authentication.AuthenticationController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.authentication',

    onLoginButton: function () {
        console.debug('LoginController onLoginButton 进入');
        var me = this;
        var myview = me.getView();
        var myviewmodel = myview.getViewModel();

        Ext.Ajax.request({
            url: BizHttpAction.login.url,
            method: BizHttpAction.login.method,
            params: {
                username: myviewmodel.get('username'),
                password: myviewmodel.get('password'),
                rememberme: myviewmodel.get('rememberme')
            },
            disableCaching: false,
            success: function (response, opts) {
                var respObj = Ext.JSON.decode(response.responseText);
                if (respObj.success == true) {
                    localStorage.setItem("TutorialLoggedIn", true);
                    window.location.href = '#home';
                } else {
                    Ext.Msg.alert("提示", respObj.message);
                }
            },
            failure: function (response, opts) {
                var respObj = Ext.JSON.decode(response.responseText);
                Ext.MessageBox.alert('提示', respObj.message);
            }
        });

        // var myform = me.getView().lookup('loginForm').getForm();
        // //console.debug('myform', myform);
        // //判断form是否处于有效状态, 即各个需要验证的field是否通过了验证
        // if (!myform.isValid()) {
        //     Ext.MessageBox.alert('信息提示', '表单验证未通过, 请检查必填项');
        //     return;
        // }
        // myform.submit({
        //     clientValidation: true,
        //     submitEmptyText: false,
        //     disabled: true,
        //     waitMsg: '提交中...',
        //     url: BizHttpAction.login.url,
        //     method: BizHttpAction.login.method,
        //     params: {
        //         // 'draft': btn.actiontype === 'draft' ? true : false,
        //         // 'namingParams': Ext.JSON.encode(paramGridDataArray),
        //         // 'headers': Ext.JSON.encode(headers)
        //     },
        //     success: function (form, action) {
        //         if (action.result.success) {
        //             // Set the localStorage value to true
        //             localStorage.setItem("TutorialLoggedIn", true);
        //             window.location = 'home';
        //         } else {
        //             Ext.Msg.alert("提示", respObj.message);
        //         }
        //     },
        //     failure: function (form, action) {
        //         var alertMsg;
        //         if (action.result && action.result.message) {
        //             alertMsg = action.result.message;
        //         } else {
        //             alertMsg = '登陆失败, 请联系系统管理员'
        //         }
        //         Ext.Msg.alert('登陆失败', alertMsg, function () {
        //         });
        //     }
        // });
    }
});